using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HotUpdate.UI
{
    public class BookPage
    {
        public int index = -1;
        public Sprite bookSprite;

        public BookPage(int index, Sprite bookSprite)
        {
            this.index = index;
            this.bookSprite = bookSprite;
        }
    }

    public class UIBook : MonoBehaviour
    {
        public BookPage[] books;
        
        /// <summary>
        /// 主剔除
        /// </summary>
        public RectTransform mainClip;

        public RectTransform nowLeftBook;
        public RectTransform nowRightBook;

        
        public RectTransform nextLeftBook;
        public RectTransform nextRightBook;


        private Vector3 page2Pos;
        private Vector3 page2Rotation;

        public Sprite GetBookPage(int index)
        {
            if (index < 0 || index >= books.Length)
            {
                throw new Exception("当前的页码超过限制");
                return default;
            }
            return books[index].bookSprite;
        }


        private void Start()
        {
            //先测试默认从右往左滑
            nowRightBook.SetParent(mainClip, true);
            nextLeftBook.SetParent(mainClip, true);
            
            // nowRightBook.transform.position = BookPanel.TransformPoint(c);
            
            page2Pos = nowRightBook.position;
            page2Rotation = nowRightBook.rotation.eulerAngles;
            
        }

        private void Update()
        {
            nowRightBook.position = page2Pos;
            nowRightBook.rotation = Quaternion.Euler(page2Rotation);
        }

        public void CalNextLeftPage()
        {
            
        }
    }
}